<?php

Yii::import('common.models._base.BaseClassImage');

class ClassImage extends BaseClassImage {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public static function isPrimaryImage($model) {
        $id = $model->getAttribute('id');
        $primaryImage = $model->getAttribute('primary_image');
        $enableImg = baseUrl() . "/images/active.png";
        $disableImg = baseUrl() . "/images/deactive.png";
        if ($primaryImage == 1) {
            echo '<img alt="Primary"  name="primary" id="imgadmin_' . $id . '" src="' . $enableImg . '"  onclick="ChangeStatus(' . $id . ',' . $model->classes_id . ')" style="cursor: pointer;" />';
        } else {
            echo '<img alt="Primary" name="primary" id="imgadmin_' . $id . '" src="' . $disableImg . '"  onclick="ChangeStatus(' . $id . ',' . $model->classes_id . ')" style="cursor: pointer;" />';
        }
    }

    public static function getPrimaryImage($classId) {
        $classImage = ClassImage::model()->findByAttributes(array('classes_id' => $classId, 'primary_image' => 1));
        if (!empty($classImage)) {
            return $classImage->photo;
        } else {
            $classImage = ClassImage::model()->findByAttributes(array('classes_id' => $classId));
            if (!empty($classImage)) {
                return $classImage->photo;
            }
        }
    }

    public static function getCoursesPrimaryImage($courseId) {
        $classImage = ClassImage::model()->findByAttributes(array('courses_id' => $courseId, 'primary_image' => 1));
        if (!empty($classImage)) {
            return $classImage->photo;
        } else {
            $classImage = ClassImage::model()->findByAttributes(array('courses_id' => $courseId));
            if (!empty($classImage)) {
                return $classImage->photo;
            }
        }
    }
     public static function isPrimaryImagecourse($model) {
        $id = $model->getAttribute('id');
        $primaryImage = $model->getAttribute('primary_image');
        $enableImg = baseUrl() . "/images/active.png";
        $disableImg = baseUrl() . "/images/deactive.png";
        if ($primaryImage == 1) {
            echo '<img alt="Primary"  name="primary" id="imgadmin_' . $id . '" src="' . $enableImg . '"  onclick="ChangeStatus(' . $id . ',' . $model->courses_id . ')" style="cursor: pointer;" />';
        } else {
            echo '<img alt="Primary" name="primary" id="imgadmin_' . $id . '" src="' . $disableImg . '"  onclick="ChangeStatus(' . $id . ',' . $model->courses_id . ')" style="cursor: pointer;" />';
        }
    }

}
